<template>
  <Dialog :title="dialogTitle" :draggable="true" v-model="dialogVisible">
    <el-form :model="form">
      <el-form-item label="项目名称:" prop="name">
        <el-input v-model="form.name" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="项目类型:" prop="specs">
        <div class="wrap flex w-[400px] flex-wrap gap-4">
          <categoryCom v-for="(cate, index) in categorys" :key="index">
            <template #top>
              <img class="w-[120px] h-[60px]" :src="cate.pic" alt="" />
            </template>
            <template #bottom>
              <el-radio v-model="form.type" :label="cate.label" :value="cate.value" />
            </template>
          </categoryCom>
        </div>
      </el-form-item>
      <el-form-item label="项目权限:" prop="auth">
        <el-radio-group v-model="form.isPrivate">
          <el-radio v-for="(item, index) in auth" :value="item.value" :key="index" :label="item.label" />
        </el-radio-group>
      </el-form-item>
      <el-form-item label="项目描述:" prop="type">
        <el-input autosize type="textarea" v-model="form.description" placeholder="请输入产品型号" />
      </el-form-item>
      <el-form-item label="" prop="type">
        <el-button type="primary" size="default" @click="sureEdit">确定修改</el-button>
        <el-button type="default" size="default" @click="closeModal">关 闭</el-button>
      </el-form-item>
    </el-form>
  </Dialog>
</template>

<script setup lang="ts">
import categoryCom from '@/views/a-gallery/categoryCom.vue'
import { cates } from '@/utils/a-common'
import { editProjectBaseInfo } from '@/api/a-project/index'

let message = useMessage()
const dialogTitle = ref('')
const dialogVisible = ref(false)
const categorys = ref(cates)
const emit = defineEmits(['success'])
const auth = [
  {
    value: 1,
    label: '私有'
  },
  {
    value: 2,
    label: '公开'
  }
]
let form = reactive({
  name: '',
  type: 1,
  isPrivate: 1,
  description: '',
})

const open = (row) => {
  dialogVisible.value = true
  form = row
}
defineExpose({ open })

const closeModal = () => {
  dialogVisible.value = false
  // 关闭后初始化form
  form = {
    name: '',
    type: 1,
    isPrivate: 1,
    description: '',
  }
}

// 确定修改
const sureEdit = async () => {
  let res = await editProjectBaseInfo(form)
  if (res) {
    closeModal()
    emit('success')
    message.success('修改成功!!!')
  }
}

</script>

<style lang="scss" scoped></style>
